home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tcclib.exe / FINDUP.C < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-18  |  906 b   |  46 lines

  1. #include <stdlib.h>
  2.  
  3. typedef struct {
  4.     int   x;
  5.     int   y;
  6.     int   Len;
  7.     int   Type;
  8.     char *Address;
  9.     int   EditFlag;
  10.     int   NumDecimals;
  11. } FieldStruc;
  12.  
  13. FindUp( FieldStruc *Field, int pos, int NUMFIELDS)
  14. {
  15.     register int i;
  16.     register int choice = -1;
  17.     register int abs1, abs2;
  18.     register FieldStruc *FS1, *FS3, *FS2=Field + pos;
  19.  
  20.     FS1 = Field;
  21.     for (i=0; i<NUMFIELDS; ++i) {
  22.         if ( i == pos )                 goto Increment;
  23.         if ( FS1->EditFlag == 0 )       goto Increment;
  24.         if ( FS1->y >= FS2->y )         goto Increment;
  25.         abs2 =  abs( FS1->x - FS2->x );
  26.         if ( abs2 > 40 )                goto Increment;
  27.         if ( choice == -1 ) {
  28.             choice = i;
  29.             FS3 = FS1;
  30.             abs1 = abs2;
  31.         }
  32.         else
  33.             if ( FS1->y > FS3->y || ( FS1->y == FS3->y && abs2 < abs1 ) ) {
  34.                 choice = i;
  35.                 FS3 = FS1;
  36.                 abs1 = abs2;
  37.             }
  38. Increment:
  39.         FS1++;
  40.     }
  41.     if ( choice == -1 )
  42.         return( pos );
  43.     else
  44.         return( choice );
  45. }
  46.